#include <string>
#include <iostream>
#include <cassert>
using namespace std;

class Solution 
{
public:
    bool isScramble(string s1, string s2) 
	{
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		if((s1.size() != s2.size()))
			return false;

		if(s1.size()==0)
			return true;

		return isScramble(s1,s2,0,0,s1.size());
    }

private:
	bool isScramble(const string& s1, const string& s2, size_t startIdx1, size_t startIdx2, size_t len)
	{
		assert(s1.size()==s2.size());

		if(len==1)
			return s1[startIdx1]==s2[startIdx2];
		

		for(size_t i=1;i<len;i++)
		{
			if((isScramble(s1,s2,startIdx1,startIdx2,i) && isScramble(s1,s2,startIdx1+i, startIdx2+i,len-i)) || 
				(isScramble(s1,s2,startIdx1,startIdx2+len-i,i) && isScramble(s1,s2,startIdx1+i, startIdx2,len-i)))
				return true;
		}
		return false;
	}
};

int main()
{
	string line1,line2;
	Solution s;
	while(getline(cin,line1))
	{
		if(line1 == "")
			break;

		getline(cin,line2);

		cout<<s.isScramble(line1,line2)<<endl;
	}
}